home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Utilities / vim-5.1 / src / STYLE < prev    next >
Encoding:
Text File  |  1998-02-18  |  3.4 KB  |  137 lines

  1.                    Vim coding style
  2.  
  3. These are the rules to use when making changes to the Vim source code.  Please
  4. stick to these rules, to keep the sources readable and maintainable.
  5.  
  6. This list is not complete.  Look in the source code for more examples.
  7.  
  8.  
  9. MAKING CHANGES
  10.  
  11. The basic steps to make changes to the code:
  12. 1. Adjust the documentation.  Doing this first gives you an impression of how
  13.    your changes affect the user.
  14. 2. Make the source code changes.
  15. 3. Check ../todo if the change affects any listed item.
  16. 4. Add a note to version.c
  17.  
  18.  
  19. USE OF COMMON FUNCTIONS
  20.  
  21. Some functions that are common to use, have a special Vim version.  Always
  22. consider using the Vim version, because they were introduced with a reason.
  23.  
  24. NORMAL NAME    VIM NAME    DIFFERENCE OF VIM VERSION
  25. free()        vim_free()    Checks for freeing NULL
  26. malloc()    alloc()        Checks for out of memory situation
  27. malloc()    lalloc()    Like alloc(), but has long argument
  28. strcpy()    STRCPY()    Includes cast to (char *), for char_u * args
  29. strchr()    vim_strchr()    Accepts special characters
  30. strrchr()    vim_strrchr()    Accepts special characters
  31. isspace()    vim_isspace()    Can handle characters > 128
  32. iswhite()    vim_iswhite()    Only TRUE for Tab and space
  33. memcpy()    vim_memmove()    Handles overlapped copies
  34. bcopy()        vim_memmove()    Handles overlapped copies
  35. memset()    vim_memset()    Uniform for all systems
  36.  
  37.  
  38. NAMES
  39.  
  40. Because of the requirement that Vim runs on as many systems as possible, we
  41. need to avoid using names that are already defined by the system.  This is a
  42. list of names that are known to cause trouble.  The name is given as a regexp
  43. pattern.
  44.  
  45. is.*()        POSIX, ctype.h
  46. to.*()        POSIX, ctype.h
  47.  
  48. d_.*        POSIX, dirent.h
  49. l_.*        POSIX, fcntl.h
  50. gr_.*        POSIX, grp.h
  51. pw_.*        POSIX, pwd.h
  52. sa_.*        POSIX, signal.h
  53. mem.*        POSIX, string.h
  54. str.*        POSIX, string.h
  55. wcs.*        POSIX, string.h
  56. st_.*        POSIX, stat.h
  57. tms_.*        POSIX, times.h
  58. tm_.*        POSIX, time.h
  59. c_.*        POSIX, termios.h
  60. MAX.*        POSIX, limits.h
  61. __.*        POSIX, system
  62. _[A-Z].*        POSIX, system
  63. E[A-Z0-9]*    POSIX, errno.h
  64.  
  65. wait        don't use as argument to a function, conflicts with types.h
  66. new        C++ reserved keyword
  67. try        Borland C++ doesn't like it to be used as a variable.
  68.  
  69. basename()    GNU string function
  70. dirname()    GNU string function
  71. get_env_value()    Linux system function
  72.  
  73.  
  74. STYLE
  75.  
  76. General rule: One statement per line.
  77.  
  78. Wrong:        if (cond) a = 1;
  79.  
  80. OK:        if (cond)
  81.         a = 1;
  82.  
  83. Wrong:        while (cond);
  84.  
  85. OK:        while (cond)
  86.         ;
  87.  
  88. Wrong:        do a = 1; while (cond);
  89.  
  90. OK:        do
  91.         a = 1;
  92.         while (cond);
  93.  
  94.  
  95. Functions start with:
  96.  
  97. Wrong:    int function_name(int arg1, int arg2)
  98.  
  99. OK:    /*
  100.      * Explanation of what this function is used for.
  101.      *
  102.      * Return value explanation.
  103.      */
  104.         int
  105.     function_name(arg1, arg2)
  106.         int        arg1;        /* short comment about arg1 */
  107.         int        arg2;        /* short comment about arg2 */
  108.  
  109. NOTE: Don't use ANSI style function declarations.  Some people still have to
  110. use compilers that don't support it.
  111.  
  112.  
  113. SPACES AND PUNCTUATION
  114.  
  115. No space between a function name and the bracket:
  116.  
  117. Wrong:  func (arg);
  118. OK:    func(arg);
  119.  
  120. Do use a space after if, while, switch, etc.
  121.  
  122. Wrong:    if(arg)        for(;;)
  123. OK    if (arg)    for (;;)
  124.  
  125. Use a space after a comma and semicolon:
  126.  
  127. Wrong:  func(arg1,arg2);    for (i = 0;i < 2;++i)
  128. OK:    func(arg1, arg2);    for (i = 0; i < 2; ++i)
  129.  
  130. Use a space before and after '=', '+', '/', etc.
  131.  
  132. Wrong:    var=a*5;
  133. OK:    var = a * 5;
  134.  
  135. In general: Use empty lines to group lines of code together.  This makes it
  136. more easy to quickly see what is being done.
  137.